import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/user/login/login.vue'
import Verify from '@/components/拉动验证码/verify.vue'
import Randompicture from '@/components/随机生成图片/randompicture.vue'
import Try from '@/components/try.vue'
import VerificationCode from '@/components/VerificationCode/VerificationCode.vue'
import Voting from '@/views/user/voting/voting.vue'
import Voting_record from '@/views/user/voting_record/voting_record.vue'
import Staff_management from '@/views/admin/staff_management.vue'
import Even_management from '@/views/admin/even_management.vue'






const routes = [
  {
    path: '/',
    name: 'login',
    redirect:'login', //重定向
    component: Login
  },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // },
  {
    path:'/Login',
    component:Login,
    
  },{
    path:'/Verify',
    component:Verify
  },{
    path:'/Randompicture',
    component:Randompicture
  },{
    path:'/VerificationCode',
    component:VerificationCode
  },{
    path:'/Voting',
    component:Voting
  },{
    path:'/Voting_record',
    component:Voting_record
  },{
    path:'/Staff_management',
    component:Staff_management
  },{
    path:'/Even_management',
    component:Even_management
  },{
    path:'/Try',
    component:Try
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  
})
// 全局后置导航守卫
router.afterEach((to,from,next) => {
  if (to.path === '/login') {
    // 到首页后清空浏览器记录
    // history.pushState(null, '', window.location.href.split('#')[0]);
    // history.go(-history.length+1)
    // history.go
    // window.history.replaceState(null, null, '/login');
    // console.log(window.history);
    
    // window.history.back
    // console.log("hhhhhhh");
     
    // console.log(window.history);
    console.log("返回首页路由监听");
    
  }
});

export default router

